﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class adminstrator_planGH : System.Web.UI.Page
{
    public OleDbConnection myConnection;
    public static readonly string sconnectionstring = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sconnectionstring);
        myConnection.Open();
        if (Session["UserName"] == null && Session["UserNo"] == null)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登录！'); parent.location.href='../login.aspx'</script>", false);

        if (!IsPostBack)
            bind();
    }
    protected void Gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Gridview1.PageIndex = e.NewPageIndex;
        bind();
    }
    protected void Gridview1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string courseNo = Gridview1.DataKeys[e.NewEditIndex][0].ToString();
        string courseName = Gridview1.DataKeys[e.NewEditIndex][1].ToString();
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>location.href='planDoctor.aspx?courseNo=" + courseNo + " &courseName=" + courseName + " ';</script>", false);
    }
    public void bind()
    {
        string mysql = "select * from PatCF order by ID_JZ ";
        OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
        OleDbDataAdapter Adapter = new OleDbDataAdapter();
        Adapter.SelectCommand = mycmd;
        DataSet myDS = new DataSet();
        Adapter.Fill(myDS);
        if (myDS.Tables.Count > 0 && myDS.Tables[0].Rows.Count > 0)
        {
            Gridview1.DataSource = myDS;
            Gridview1.DataKeyNames = new string[] { "ID_JZ", "Name", "Dname", "NUM", "Znum", "Cname", "Price", "Dsubject", "Zday" };
            Gridview1.DataBind();
        }
    }

}